$(function(){
	selectAll(1)
})
function selectAll(pageindex) {
	
	var pageindex = pageindex;
	if(pageindex==""|| pageindex==null){
		pageindex =1;
	}

	var diseasena = $("#diseasname").val();
	$.ajax({

		type : "get",
		url : "/Medical/queryAlldiseaseInfo/"+pageindex,
		async : true,
		data:{
			disease:diseasena
		},
		success : function(result) {
			console.log(result);
			
			var yetou = "";
			var operator = "";
			var yeshu = ""
				
			$.each(result.diseaseInfo, function(key, value) {
				console.log(value)
				operator += "<tr>" +
						"<td>" + value.encodingDisease + "</td>" +
						"<td>"+ value.deseaseName + "</td>" +
						"<td>" + value.reimbursementMark+ "</td>" +
						"<td>" + value.dremarks + "</td>" +
						"<td><button onclick="+"\""+"upddatedisease("+"'"+value.encodingDisease+"'"+","+"'"+value.deseaseName+"'"+","+"'"+value.reimbursementMark+"'"+","+"'"+value.dremarks+"'"+")"+"\""+">修改</button></td>" +
						"<td><button onclick="+"\""+"deletedisease("+"'"+value.encodingDisease+"'"+")"+"\""+">删除</button></td>" +
						"</tr>";
			});
			var yeshu = "<button class='shouye' onclick=fenye("+result.diseasepageInfo.navigateFirstPage+")>首页</button>";
			
			 yeshu += "<button class='sye' onclick=fenye("+
			 result.diseasepageInfo.prePage+")>上一页</button>";

			$.each(result.diseasepageInfo.navigatepageNums, function(key, value) {
				
				yeshu += "<button class='xye' onclick=fenye("+
				value+")>"+value+"</button>"

			});
			
			yeshu += "<button class='xiaye' onclick=fenye("+
			result.diseasepageInfo.nextPage+")>下一页</button>"
			
			yeshu += "<button class='weiye' onclick=fenye("+
			result.diseasepageInfo.navigateLastPage+")>尾页</button>"
			
			yeshu += "<span>&nbsp;&nbsp;&nbsp;</span>" +"<span>当前第:"+result.diseasepageInfo.pageNum+"页</span>"
			
			yeshu += "<span>&nbsp;&nbsp;&nbsp;</span>"+"<span>总页数：  "+result.diseasepageInfo.pages+"页</span>"
			
			
			
			console.log(operator)
			$("#showall").html(operator);
			$("#nav").html(yeshu);
			if(result.diseasepageInfo.navigateLastPage==result.diseasepageInfo.pageNum){
				$(".xiaye").attr("disabled",true);
			}
		},
		error : function() {

		}

	});
	return false;
}

function fenye(ye) {
	selectAll(ye);
	
}

function upddatedisease(encodingDisease,deseaseName,reimbursementMark,dremarks){
	
	var form = "<form id='upda'>疾病编号:<input name='encodingDisease' value="+"'"+encodingDisease+"'"+"/></br>病种名称:<input name='deseaseName' value="+"'"+deseaseName+"'"+"/></br>报销标志:<input name='reimbursementMark' value="+"'"+reimbursementMark+"'"+"/></br>"
	+"备注:<input name='dremarks' value="+"'"+dremarks+"'"+"/></br><button>取消</button><button onclick='upddatedinfo()'>更新</button></form>"	
	
	$("#up").html(form);

}

function upddatedinfo(){
	
	$.ajax({
		
		type:"get",
		url:"/Medical/updatediseaseInfo",
		data:$("#upda").serialize(),
		async:true,
		success:function(data){
			selectAll("1");
		},error:function(){
			console.log(ewqeqe)
		}
	});
	
}

function deletedisease(diseaseid){
	
	$.ajax({
		type:"get",
		url:"/Medical/deletediseaseInfo/"+diseaseid,
		async:true,
		success:function(result){
			selectAll(1)
			alert("成功删除"+result+"条记录")
		},error:function(){
			alert("删除失败")
		}
		
	})
	
}

function insertdisease(){
	
	var form = "<form id='insert' method='get'>疾病编号:<input name='encodingDisease' value="+"''"+"/></br>病种名称:<input name='deseaseName' value="+"''"+"/></br>报销标志:<input name='reimbursementMark' value="+"''"+"/></br>"
	+"备注:<input name='dremarks' value="+"''"+"/></br><button>取消</button><button onclick='insertinfo()'>添加</button></form>"	
	
	$("#in").html(form);
}
function insertinfo(){
	
	$.ajax({
		
		type:"get",
		url:"/Medical/insertDiseaseInfo",
		async:true,
		data:$("#insert").serialize(),
		success:function(result){
			alert("成功增加"+result+"一条记录")
		},error:function(){
			alert("新增失败")
		}
	})
}



